aboutsummaryrefslogtreecommitdiff
path: root/src/pages/[...path].tsx
diff options
context:
space:
mode:
Diffstat (limited to 'src/pages/[...path].tsx')
-rw-r--r--src/pages/[...path].tsx39
1 files changed, 21 insertions, 18 deletions
diff --git a/src/pages/[...path].tsx b/src/pages/[...path].tsx
index ea67d17..a49286d 100644
--- a/src/pages/[...path].tsx
+++ b/src/pages/[...path].tsx
@@ -4,23 +4,30 @@ import ReactMarkdown from 'react-markdown';
import Head from 'next/head';
import Emoji from '../Emoji';
import Image from '../Image';
-import deepReadDir from '../deepReadDir';
import emojiPlugin from '../emojiPlugin';
-import fs from 'fs';
import remarkGemoji from 'remark-gemoji';
+import benzinConfig from '../benzinConfig';
-
-const MARKDOWN_DIR = '../eug-vs-xyz/src';
-const EMOJI_DIR = 'public/emoji';
-
-const transformLinkURI = (uri: string): string => {
+const transformLinkUri = (uri: string): string => {
return uri.match(/(.*)\.md/)?.[1] || uri;
}
+const transformImageUri = (uri: string): string => {
+ return uri.startsWith('http') ? uri : benzinConfig.CDN + uri;
+}
+
+export const config = {
+ unstable_runtimeJS: false,
+};
+
export const getStaticProps = async (context: GetStaticPropsContext) => {
- const path = _.isArray(context.params?.path) && context.params?.path || [context.params?.path];
- const markdownSource = fs.readFileSync(`${MARKDOWN_DIR}/${path?.join('/')}.md`).toString();
- const emojiFileNames = fs.readdirSync(EMOJI_DIR);
+ const path = _.compact(_.isArray(context.params?.path)
+ ? context.params?.path
+ : [context.params?.path]
+ );
+
+ const markdownSource = await benzinConfig.adapter.getMarkdownSource(benzinConfig.CDN, path);
+ const emojiFileNames = await benzinConfig.adapter.getEmojiFileNames(benzinConfig.CDN);
return {
props: {
@@ -32,12 +39,8 @@ export const getStaticProps = async (context: GetStaticPropsContext) => {
}
export const getStaticPaths = async () => {
- const globalPaths = await deepReadDir(MARKDOWN_DIR);
- const paths = globalPaths
- .map(globalPath => globalPath.match(`${MARKDOWN_DIR}/(.*)\.md`)?.[1] )
- .filter(p => p)
- .map(p => p?.split('/'))
- .map(path => ({ params: { path } }));
+ const paths = await benzinConfig.adapter.getStaticMarkdownPaths(benzinConfig.CDN);
+
return {
paths,
fallback: 'blocking',
@@ -54,7 +57,8 @@ const Page: NextPage = ({ markdownSource, emojiFileNames }: any) => {
</Head>
<main>
<ReactMarkdown
- transformLinkUri={transformLinkURI}
+ transformLinkUri={transformLinkUri}
+ transformImageUri={transformImageUri}
rehypePlugins={[emojiPlugin(emojiFileNames), remarkGemoji]}
components={{
emoji: Emoji,
@@ -74,4 +78,3 @@ const Page: NextPage = ({ markdownSource, emojiFileNames }: any) => {
};
export default Page;
-